#include <bits/stdc++.h>
using namespace std;

struct Node{
    int fir,las;
    bool operator <(Node o) {
        return las < o.las;
    }
}tag[100005];

long long d[100005],v[100005],a[100005],p[100005],cnt[1000005],cnt2[1000005];

int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    long long t,n,m,l,maxv,ans1 = 0,ans2 = 0;
    cin >> t;
    for(int i = 0;i < t;i++) {
        cin >> n >> m >> l >> maxv;
        ans1 = 0;
        ans2 = 0;
        for(int j = 0;j < n;j++) {
            cin >> d[j] >> v[j] >> a[j];
            tag[j].fir = 0;
            tag[j].las = m;
        }
        for(int j = 1000002;j >= 0;j--) {
            cnt[j] = -1;
            cnt2[j] = -1;
        }
        for(int j = 0;j < m;j++) {
            cin >> p[j];
            cnt[p[j]] = j;
            cnt2[p[j]] = j;
        }
        for(int j = 1000002;j >= 0;j--) {
            if(cnt[j] == -1) cnt[j] = cnt[j + 1];
        }
        for(int j = 1;j < 1000003;j++) {
            if(cnt2[j] == -1) cnt2[j] = cnt2[j - 1];
        }
        for(int j = 0;j < n;j++) {
            if(cnt[d[j]] == -1) continue;
            if(a[j] > 0) {
                long long sa = maxv * maxv - v[j] * v[j],sb = 2 * a[j];
                long long now_s;
                if(sa % sb == 0) now_s = sa / sb;
                else now_s = sa / sb + 1;
                if(now_s < 0) {
                    tag[j].fir = cnt[d[j]];
                    tag[j].las = m - 1;
                    ans1++;
                }
                else {
                    now_s += d[j];
                    if(cnt[now_s] != -1) {
                        tag[j].fir = cnt[now_s];
                        tag[j].las = m - 1;
                        ans1++;
                    }
                }
            }
            else if(a[j] == 0) {
                if(v[j] > maxv) {
                    ans1++;
                    tag[j].fir = cnt[d[j]];
                    tag[j].las = m - 1;
                }
            }
            else {
                long long sa = maxv * maxv - v[j] * v[j],sb = 2 * a[j];
                long long now_s;
                sa = -sa;
                sb = -sb;
                now_s = sa / sb;
                if(now_s >= 0) {
                    now_s += d[j];
                    if(cnt2[now_s] > cnt2[d[j]]) {
                        ans1++;
                        tag[j].fir = cnt[d[j]];
                        tag[j].las = cnt2[now_s];
                    }
                }
            }
        }
        sort(tag,tag + n);
        int last = -1;
        for(int j = 0;j < n;j++) {
            if(tag[j].fir > last) {
                ans2++;
                last = tag[j].las;
            }
            //cout << tag[j].fir << " " << tag[j].las << endl;
        }
        cout << ans1 << " ";
        if(last == m) cout << m;
        else cout << m - ans2;
        cout << endl;
    }
    return 0;
}
